<?php
session_start();
if (!isset($_SESSION["adminId"])) {
    echo "<script>window.location.href='login.html';</script>";
} else {

    $adminId = $_SESSION['adminId'];
    $root = $_SESSION['p'];
    $root = explode(",", $root);
    $root1 = $root[0];
    $root2 = $root[1];
    $root3 = $root[2];
    $root4 = $root[3];
    $url = $_SERVER["QUERY_STRING"];
    $id = str_replace("id=", '', $url);
    switch ($id) {
        case 1:
            $title = "国别化（泰国）汉语教学资源库及中国文化传播平台--资源汇集与管理子平台";
            break;
        case 2:
            $title = "国别化（泰国）汉语教学资源库及中国文化传播平台--云教育服务子平台";
            break;
        case 3:
            $title = "国别化（泰国）汉语教学资源库及中国文化传播平台--智能分析子平台";
            break;
        case "":
            echo "<script>window.location.href='login.html';</script>";

    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>易汉语 后台管理</title>
    <link rel="stylesheet" href="css/layui.css" id="layui">
    <link rel="stylesheet" href="css/theme/default.css" id="theme">
    <link rel="stylesheet" href="css/kitadmin.css" id="kitadmin">
    <link rel="stylesheet" href="font/newFont/iconfont.css">
</head>

<body class="layui-layout-body kit-theme-default">
<div class="layui-layout layui-layout-admin">
    <!-- header -->
    <div class="layui-header">
        <div class="layui-logo" style="width: 100%">
            <div class="layui-logo-toggle" kit-toggle="side" data-toggle="on">
                <i class="layui-icon">&#xe65a;</i>
            </div>
            <div class="layui-logo-brand" style="width: 100%">
                <a href="#/"><?php echo $title ?></a>
            </div>
        </div>
        <div class="layui-layout-left">
        </div>
        <div class="layui-layout-right">
            <ul class="kit-nav" lay-filter="header_right">
                <li class="kit-item" kit-target="help">
                    <a href="javascript:;">
                        <i class="layui-icon">&#xe607;</i>
                        <span>帮助</span>
                    </a>
                </li>
                <li class="kit-item">
                    <a href="javascript:;">
              <span>
                  <span
                          id="userName"><?php echo $_SESSION["name"] ?></span>
              </span>
                    </a>
                    <ul class="kit-nav-child kit-nav-right">
                        <li class="kit-item">
                            <a href="javascript:;" id="pass">
                                <i class="layui-icon">&#xe612;</i>
                                <span>修改密码</span>
                            </a>
                        </li>
                        <li class="kit-item" kit-target="setting">
                            <a href="javascript:;">
                                <i class="layui-icon">&#xe614;</i>
                                <span>设置</span>
                            </a>
                        </li>
                        <li class="kit-nav-line"></li>
                        <li class="kit-item">
                            <a id="clearSession">
                                <i class="layui-icon">&#x1006;</i>
                                <span>注销</span>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <!-- silds -->
    <div class="layui-side" kit-side="true">
        <div class="layui-side-scroll">
            <div id="menu-box">
                <ul class="kit-menu">
                    <li class="kit-menu">
                        <a href="choice.php">
                            <i class="layui-icon ">&#xe68e;</i>
                            <span>首页</span>
                        </a>
                    </li>
                    <?php
                    if ($root3 == 1 && $id == 3) {
                        echo "    
                   <li class=\"kit-menu\">
                        <a href=\"#/userStat\" class='aItem'>
                           <span class=\"icon iconfont\">&#xe60e;</span>
                            <span>用户统计</span>
                        </a>
                    </li>
                   <li class=\"kit-menu\">
                        <a href=\"#/startUp\" class='aItem'>
                            <i class=\"layui-icon \">&#xe62c;</i>
                            <span>启动统计</span>
                        </a>
                    </li>
                             <li class=\"kit-menu\">
                        <a href=\"#/activeStat\" class='aItem'>
                       <i class=\"layui-icon \">&#xe600;</i>
                            <span>激活统计</span>
                        </a>
                    </li>
                    <li class=\"kit-menu\">
                        <a href=\"#/startList\" class='aItem'>
                         <i class=\"layui-icon \">&#xe615;</i>
                            <span>单设备查询</span>
                        </a>
                    </li>
           
                    <li class=\"kit-menu\">
                        <a href=\"#/teacherStat\" class='aItem'>
                                <i class=\"layui-icon \">&#xe60a;</i>
                            <span>教师查询</span>
                        </a>
                    </li>";
                    }
                    if ($root3 == 1 && $id == 1) {
                        echo "      <li class=\"kit-menu\">
                        <a href=\"#/listAdmin\" class='aItem'>
                   <i class=\"layui-icon \">&#xe66f;</i>
                           管理员管理</span>
                        </a>
                    </li>    
                       <li class=\"kit-menu\">
                        <a href=\"#/school\" class='aItem'>
                            <i class=\"layui-icon \">&#xe66c;</i>
                            <span>区域管理</span>
                        </a>
                    </li>
                <li class=\"kit-menu-item\">
                        <a  class='aItem child'>
                              <i class=\"layui-icon \">&#xe679;</i>
                            <span>激活码管理</span>
                        </a>
                         <ul class=\"kit-menu-child layui-anim layui-anim-upbit\">
                <li class=\"kit-menu-item\">
               <a href=\"#/activeCode\" class='aItem'>
                    <i class=\"layui-icon\"></i>
                    <span>教师激活码管理</span>
                  </a>
                </li>
              <li class=\"kit-menu-item\">
               <a href=\"#/studentActiveCode\" class='aItem'>
                    <i class=\"layui-icon\"></i>
                    <span>学生激活码管理</span>
                  </a>
                </li>
          
              </ul>
                    </li>";
                    }
                    if ($root3 == 1 && $id == 2) {
                        echo "  <li class=\"kit-menu\">
                        <a href=\"#/resourceList\" class='aItem'>
                                  <i class=\"layui-icon \">&#xe653;</i>
                            <span>资源管理</span>
                        </a>
                    </li>
                    <li class=\"kit-menu\">
                        <a href=\"#/version\" class='aItem'>
                                  <i class=\"layui-icon \">&#xe62e;</i>
                            <span>版本管理</span>
                        </a>
                    </li>
                    <li class=\"kit-menu\">
                        <a href=\"#/notice\" class='aItem'>
                         <i class=\"layui-icon \">&#xe645;</i>
                            <span>公告管理</span>
                        </a>
                    </li>
                    <li class=\"kit-menu\">
                        <a href=\"#/itemBank\" class='aItem'>
                                <i class=\"layui-icon \">&#xe62f;</i>
                            <span>上传题库资源</span>
                        </a>
                    </li>";

                    }
                    ?>
                </ul>
            </div>
        </div>
    </div>
    <!-- main -->
    <div class="layui-body" kit-body="true">
        <router-view></router-view>
    </div>
    <!-- footer -->
    <div class="layui-footer" kit-footer="true">
        <div style="width:400px; height:400px;" class="load-container load1">
            <div class="loader">2019 © 国别化（泰国）汉语教学资源库及中国文化传播平台</div>
        </div>
    </div>
</div>

<form class="layui-form" action="" id="passBox" style="display: none;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>修改密码</legend>
    </fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">旧密码</label>
        <div class="layui-input-inline">
            <input type="password" name="used_pass" id="used_pass" required lay-verify="used_pass" placeholder="请输入旧密码"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux" id="message"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input type="password" name="new_pass" id="new_pass" required lay-verify="new_pass" placeholder="请输入新的密码"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux" id="message1"></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <a class="layui-btn layui-btn-disabled" id="update_pass">立即修改</a>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<input type="text" value="<?php echo $adminId ?>" id="adminId" style="display: none;">
</body>
<script type="text/javascript" src="js/login/jquery.min.js"></script>
<script src="polyfill.min.js"></script>
<script src="layui.js"></script>
<script src="kitadmin.js"></script>
<script src="mockjs-config.js"></script>
<script type="text/javascript" src="js/config.js"></script>
<script type="text/javascript" src="js/jQuery.md5.js"></script>
<script>
    var loginApi = api.login;  //读取登录接口
    var used = "", newPass = "", adminId = "";
    $(document).ready(function () {
        $("#clearSession").click(function () {
            Cancellation();
        });
        adminId = $("#adminId").val();
        $("#pass").click(function () {
            modify_pass_box();
        });
        console.log(getBrowser());
        //监听密码输入框
        $("#used_pass").bind('input propertychange', function () {
            var user = $("#used_pass").val();
            if (user.length > 5) {
                used = $.md5(user);
                $("#message").html("<a style='color:green'><i class='layui-icon'>&#x1005;</i>输入正确</a>");
                if (newPass.length > 5) {
                    $("#update_pass").removeClass("layui-btn-disabled");
                }
                else {
                    $("#update_pass").addClass("layui-btn-disabled");
                }
            }
            else {
                $("#update_pass").addClass("layui-btn-disabled");
                $("#message").html("<a style='color:red'> <i class='layui-icon'>&#x1007;</i>长度必须大于六位</a>");
            }
        });
        $("#new_pass").bind('input propertychange', function () {
            var new_pass = $("#new_pass").val();
            if (new_pass.length > 5) {
                new_pass = $.md5(new_pass);
                newPass = new_pass;
                $("#update_pass").removeClass("layui-btn-disabled");
                $("#message1").html("<a style='color:green'><i class='layui-icon'>&#x1005;</i>输入正确</a>");
            } else {
                $("#update_pass").addClass("layui-btn-disabled");
                $("#message1").html("<a style='color:red'> <i class='layui-icon'>&#x1007;</i>长度必须大于六位</a>");
            }
        });

        //提交修改的密码
        $("#update_pass").click(function () {
            mmodify_pass();
        });
    });
    //点击刷新兼容ie浏览器
    $(".aItem").click(function () {

        if (browser == "IE") {
            window.location.reload();
        }
        else {
        }
    });
    layui.use("admin");

    //注销函数
    function Cancellation() {
        layer.confirm('确定注销吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            window.location.href = 'php/clearSession.php';
        }, function () {

        });

    }

    //修改密码
    function modify_pass_box() {
        personWin = layer.open({
            type: 1,
            shade: false,
            area: ['50%', '50%'], //宽高
            title: false, //不显示标题
            content: $('#passBox'),
            cancel: function () {
                document.getElementById("passBox").style.display = "none";
            }
        });
    }

    function mmodify_pass() {
        $.ajax({
            type: 'post',
            cache: 'false',
            url: loginApi,
            data: {
                "action": "modifyPwd",
                "adminId": adminId,
                "oldPwd": used,
                "newPwd": newPass

            },
            dataType: 'json',
            success: function (res) {
                layer.msg(res.msg);
                console.log(used, newPass);
                if (res.code == 0) {
                    layer.msg("修改成功", {time: 500, icon: 6});
                    parent.layer.close(personWin);

                    var time = setInterval(cancelSession, 1000), i = 2;

                    function cancelSession() {
                        switch (i) {
                            case 0:
                                window.location.href = 'php/clearSession.php';
                                clearInterval(time);
                        }

                        i--;
                    }


                }
            }, error: function (res) {
                layer.msg("修改失败");
            }
        });

    }

</script>
</html>